home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / bitmaphead.c next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  1.9 KB  |  66 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: bitmaphead.c,v 1.1 89/03/17 08:20:51 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/bitmaphead.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/bitmaphead.c,v $$Revision: 1.1 $";
  12.  
  13.  
  14. #include    "dump.h"
  15. #include    "bitmap.h"
  16. #include    <stdio.h>
  17.  
  18.  
  19. /*    Read the header of a bitmap (aka icon) file using the given FILE
  20.     pointer, fp.
  21.     Return 0 if the file isn't in bitmap format or is unreadable.
  22.     Otherwise, return "true" (non-zero) and populate the integers
  23.     pointed at by:
  24.         wp    width of the bitmap in bits
  25.         hp    height of bitmap in bits
  26.         dp    depth of bitmap in bits
  27.         size1p    number of bytes in a single line (including padding)
  28. */
  29.     
  30. int
  31. bitmaphead( fp, wp, hp, dp, size1p )
  32. FILE    *fp;
  33. int    *wp, *hp, *dp, *size1p;
  34. {
  35.     struct b_header    head;
  36.     
  37.     if( fread( (char *)&head, B_OHSIZE, 1, fp ) != 1 )
  38.         return  0;
  39.     if( B_ISHDR8( &head ) ) {    /* modern, self-describing
  40.                     bitmap, 8-bit alignment */
  41.         if( fread( &head.depth, sizeof head - B_OHSIZE, 1, fp ) != 1 )
  42.             return  0;
  43.         B_GETHDR8( &head, *wp, *hp, *dp );
  44.         *size1p = B_SIZE8(*wp, 1, *dp);
  45.     }
  46.     else if( B_ISHDR32( &head ) ) {    /* 1 bit deep, 32 bits align */
  47.         B_GETOLDHDR( &head, *wp, *hp );
  48.         *size1p = B_SIZE32(*wp, 1, 1);
  49.         *dp = 1;
  50.     }
  51.     else if ( B_ISHDR16(&head) ) {    /* 1 bit deep, 16 bits align */
  52.         B_GETOLDHDR( &head, *wp, *hp );
  53.         *size1p = B_SIZE16(*wp, 1, 1);
  54.         *dp = 1;
  55.     }
  56.     else if ( B8_ISHDR(&head) ) {    /* 8 bits deep, 16 bits align */
  57.         B_GETOLDHDR( &head, *wp, *hp );
  58.         *size1p = B8_SIZE(*wp, 1);
  59.         *dp = 8;
  60.     }
  61.     else {
  62.         return  0;
  63.     }
  64.     return  1;
  65. }
  66.